<?php

/*
 * Project_Name: Your node
 * Coder: Nguyễn Trần Minh Trung
 */

class Controller {

    
    public static $a_Con = array('localhost', 'root', '', 'qlcf_web');
    protected $lan;

    function __construct() {
        $this->check_Con();
        $this->check_main_seg();
    }

    private function check_Con() {
        require DEF_PATH . 'lib/Connect.php';
        try {
            new Connect(self::$a_Con, 'utf8');
        } catch (Exception $exc) {
            echo 'ssss';
        }
    }

    private function check_main_seg() {
        session_start();
        $url = new Clean_Url();
        //check ajax request
        if (isset($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') {
            require DEF_PATH . 'controller/Con_Ajax.php';
            $segment_ajax = $url->main_Segment(array('', 'cate_Menu', 'distris_SB', 'to_Cate', 'list_city', 'get-lst-sto', 'like_box', 'dang-nhap', 'login', 'to_info', 'cate_Menu', 'like'));
            if ($segment_ajax != 'loi') {
                $this->ajax_con($segment_ajax);
            }
        } else {
            require DEF_PATH . 'controller/Con_Temp.php';
            $segment = $url->main_Segment(array('', 'default', 'logout', 'breadcrumb', 'dia-diem', 'trang-chu', 'nguoi-dung', 'dang-ky', 'hen-ho', 'khong-tim-thay-trang'));
            if ($segment != 'loi') {
                $this->def_con($segment);
            } else {
                //find location
                $Pre = new Prepare('default');
                $Pre->get_Model('Model');
                $Pre->get_Model('cate');
                $cate = new cate(Controller::$a_Con);
                $lst_cate = $cate->get_ResultA_One(($cate->get_loca_by_Dad_Tag()), MYSQLI_NUM);
                $segment = $url->main_Segment($lst_cate);
                $Temp = new Con_Temp();
                if ($segment != 'loi') {
                    $Temp->dia_diem(str_replace('_', '-', $segment));
                } else {
                    $Temp->loi();
                }
            }
        }
    }

    private function def_con($segment) {
        $Temp = new Con_Temp();
        $Temp->{$segment}();
    }

    private function ajax_con($segment) {
        $ajax = new Con_Ajax();
        $ajax->{$segment}();
    }

    static function get_View() {
        require DEF_PATH . 'view/View.php';
    }

}
